<?php

require_once('rb.php');
R::setup('mysql:host=ftp.giemiebier.nl:3306;dbname=personify', 'school', 'admin123');
R::debug(true);
if ($pagetree[2] != "" && isset($pagetree[2])) {
    $id = $pagetree[2];
} else {
    $id = "";
}

$pending = R::load('pending', $id);
if ($pending != null) {

    $return['valid'] = true;
    
    $userid1 = $pending->userid1;
    $userid2 = $pending->userid2;
    R::trash($pending);

    $connection = R::dispense('connections');
    $connection->userid1 = $userid1;
    $connection->userid2 = $userid2;
    R::store($connection);

    $connection2 = R::dispense('connections');
    $connection2->userid1 = $userid2;
    $connection2->userid2 = $userid1;
    R::store($connection2);
} else {
    $return['error'] = "Something went wrong."; 
}

echo json_encode($return);
?>
